const fs = require('fs')
const path = require('path')
const lessVarsToJS = require('less-vars-to-js')

const lessThemeVars = lessVarsToJS(
  fs.readFileSync(path.resolve(__dirname, 'assets/style/vars.less'), 'utf8')
)

module.exports = {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' },
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
    ],
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
    'ant-design-vue/dist/antd.less',
    '@assets/style/common.less'
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '~/plugins/antd-ui',
    '~/plugins/axios',
    '~/plugins/mixins',
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    '@nuxtjs/eslint-module',
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    // Doc: https://github.com/nuxt-community/dotenv-module
    '@nuxtjs/dotenv',
    // Doc: https://github.com/nuxt-community/universal-storage-module
    '@nuxtjs/universal-storage',
    '@nuxtjs/style-resources'
  ],
  storage: {
  },

  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
    baseURL: process.env.BASE_URL,
    credentials: true, // 携带 cookie
  },
  /*
  ** Build configuration
  */
  build: {
    loaders: {
      less: {

        lessOptions: {
          // resources: [path.resolve(__dirname, 'assets/style/mixin.less')],
          javascriptEnabled: true,
          modifyVars: lessThemeVars,
        },
      },
    },
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
    },
  },
  styleResources: {
    less: [
      '@assets/style/mixin.less'
    ]
  },
  serverMiddleware: [
    '~/middleware/router',
  ],
}
